package org.example.design.decorator.itf.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Classname LoginSsoDecorator01
 * @Description 原始方式
 * @Date 2020/11/5 9:49 上午
 * @Created by xiangjd
 */
public class LoginSsoDecorator01 extends SsoInterceptor {
    private static Map<String, String> authMap = new ConcurrentHashMap<String, String>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    @Override
    public boolean prehandle(String requset, String response, Object handle) {
        //模拟cookie
        String ticket = requset.substring(1, 8);
        //模拟检验
        boolean success = ticket.equals("success");
        if (!success) {
            return false;
        }
        String userId = requset.substring(9);
        String method = authMap.get(userId);

        return "queryUserInfo".equals(method);
    }
}
